<template>
  <el-container class="main_con">
    <div class="filter_con ds_block">
      <div class="button_area"><el-button v-has type="primary" size="medium" @click="addItem">新增系统表单</el-button></div>

      <div class="filter_area">
        <label class="mr_15 mt_15">表单类型</label>
        <el-select  clearable  v-model="obj.source" size="medium" placeholder="请选择" class="mr_15 mt_15">
          <el-option v-for="item in sourcelist" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
        <el-button @click="search" size="medium">搜索</el-button>
      </div>
    </div>
    <div class="list_con">
      <el-table :data="list">
        <el-table-column prop="id" label="表单模板ID"></el-table-column>
        <el-table-column prop="title" label="表单名称"></el-table-column>
        <el-table-column prop="title" label="表单类型">
          <template slot-scope="scope">
            <span>{{ scope.row.source | getsource }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <span>{{ scope.row.status ? '启用' : '禁用' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button v-has type="text" @click="EnableHandle(scope.row)">{{ scope.row.status == 1 ? '禁用' : '启用' }}</el-button>
            <el-button v-has type="text" @click="EditHandle(scope.row.id)">编辑</el-button>
            <el-button v-has type="text" @click="DelHandle(scope.row.id)">删除</el-button>
            <el-button v-has type="text" @click="answerlist(scope.row.id)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="table_footer" style="justify-content: flex-end;">
        <el-pagination @current-change="ChangeCurrent" class="pages" background layout="prev, pager, next" :total="total"></el-pagination>
      </div>
    </div>
    <!--  <el-dialog title="提交记录" :visible.sync="show_answer" width="800px">

    </el-dialog> -->
  </el-container>
</template>

<script>
import {formtemplatelist, delform, formstatus} from '@/api/mall/systemform';
// import answer from
export default {
  data() {
    return {
      page: 1,
      size: 10,
      list: [],
      total: 1,
      obj: {
        source: ''
      },
      sourcelist: [{name: '下单表单', id: 0}, {name: '商品表单', id: 1}]
    };
  },
  mounted() {
    this.getlist();
  },
  filters: {
    getsource(source) {
      if (source == 0) {
        return '下单表单';
      } else if (source == 1) {
        return '商品表单';
      }
    }
  },
  methods: {
    addItem() {
      this.$router.push('/systemform/item');
    },
    search(){
      this.page=1
      this.getlist()
    },
    getlist() {
      formtemplatelist({
        page: this.page,
        size: 10,
        source: this.obj.source,
        status: ''
      }).then(res => {
        this.list = res.msg.data;
        this.total = res.msg.total;
      });
    },
    EditHandle(id) {
      this.$router.push({path: '/systemform/item', query: {id: id}});
      // this.$route.push({})
    },
    answerlist(id) {
      this.$router.push({path: '/systemform/answer', query: {id: id}});
    },
    //启用，禁用
    EnableHandle(data) {
      let _this = this;
      let status = Number(data.status != 1);
      this.$confirm(status ? '确认启用？' : '确认禁用？')
        .then(_ => {
          // let params = data;
          // params.status = status;
          let params = {
            status: status,
            id: data.id
          };
          formstatus(params).then(res => {
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    DelHandle(id) {
      let _this = this;
      this.$confirm('确认删除？')
        .then(_ => {
          delform(id).then(res => {
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    //切换页码
    ChangeCurrent(page) {
      this.page = page;
      this.getlist();
    }
  }
};
</script>

<style></style>
